﻿using System;
using System.Collections.Generic;
using Hi_Baidu.Packet;
using Hi_Baidu.Net;
using System.Text;
namespace Hi_Baidu
{
    /// <summary>
    ///     网络信息池事件类
    /// </summary>
    public class NetworkMessagePoolEvent
    {
        public NetworkMessagePoolEvent()
        {
            for (int i = 0; i < Globle.udpPortListenerManager.GetMember().Count; i++)
            {
                 (Globle.udpPortListenerManager.GetMember()[i] as PortListener).GetMessageListener().NetworkMessagePool.OnInsertedData +=new EventHandler<UMFramework.Network.Network_MessagePool.OnInsertedDataEventArgs>(NetworkMessagePool_OnInsertedData);
            }
        }

        void NetworkMessagePool_OnInsertedData(object sender, UMFramework.Network.Network_MessagePool.OnInsertedDataEventArgs e)
        {
            Dictionary<String,byte[]> Order = e.MessagePool.GetXmlProtocolData();
            if (Order!= null)
            {
                //创建解析器指针
                IParser TempParser;
                //获取解析器
                if ((TempParser = (PackageHelper.FindParser(PackageHelper.GetProtocol(Order)))) != null)
                {
                    //解析出收包
                    NetControl.processorRouter.PacketArrived(TempParser.ParserInPackage(Order));
                }
            }
        }
    }
}
